|
|
 |
|
|
|
|
next_time = next_time + ms_per_frame
WaitTill next_time
If Not Playing Then Exit For
Next i
End Sub |
|
|
|
|
|
|
|
|
Note that this code does not save palette information, so it works only in color modes that use more than 8 bits per pixel. |
|
|
|
|
|
|
|
|
This technique saves some overhead because you store only pixel values rather than a whole picture box control for each bitmap, which means you can store more images in memory without paging. GetBitmapBits and SetBitmapBits do not free you completely from paging problems, however. If you load too much data, your program will page, and the program will slow dramatically. |
|
|
|
|
|
|
|
|
Another advantage to storing picture data in an array is that you can store the array in single file. Then your program needs to load only this file instead of a series of files. The single file takes roughly as much disk space as the series of files, so you will not save much disk space, but you can reduce the clutter on your disk. |
|
|
|
|
|
|
|
|
Example program PlayBits uses this technique to display images. In one test on a 133MHz Pentium, PlayBits displayed 266 frames per second. This makes it slower than programs PlayFast and PlayWait. Its advantage over those programs is that it can save and load a series of images in a sequence file with a .seq extension. |
|
|
|
|
|
|
|
|
The following code shows how PlayBits saves and loads sequence files. The SaveSequence subroutine stores the number of images, size of the display picture box, and number of bytes per image in the file. It then writes the entire array of image information in a single Put statement. This is much faster than writing the images into the file one at a time. |
|
|
|
|
|
|
|
|
Subroutine LoadSequence reloads the number of images, size of the picture box, and number of bytes per image. It sizes the image byte array and then reads the image data in a single Get statement. |
|
|
|
 |
|
|
|
|
' Save all the images in a single file. Private Sub SaveSequence(file_name As String)
Dim fnum As Integer
' Open the file. fnum = FreeFile
Open file_name For Binary Access Write As #fnum
' Save the number of frames and the frame size. Put #fnum, , NumImages
Put #fnum, , CSng(picCanvas.Width)
Put #fnum, , CSng(picCanvas.Height)
Put #fnum, , BytesPerImage |
|
|
|
|
|